#include "denglu.h"
#include "ui_denglu.h"
#include<QIcon>
#include<QToolButton>
#include "widget.h"
#include<QMessageBox>
#include"qmessagebox.h"
denglu::denglu(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::denglu)
{
    ui->setupUi(this);

    this->setWindowTitle("贪吃蛇聊天室");

    this->setWindowIcon(QIcon(":/image/back_two.jpg"));

    QList<QString> namelist;
    namelist<<"玩家1"<<"玩家2"<<"玩家3"<<"玩家·4";
    QStringList iconnamelist;
    iconnamelist<<"one"<<"two"<<"three"<<"four";
    QVector<QToolButton *>vector;
    for(int i=0;i<4;i++)
    {
        QToolButton *btn=new QToolButton(this);
        if(i==0)
        {
            btn->setIcon(QPixmap(QString(":/image/one.jpg").arg(iconnamelist[i])));
            btn->setIconSize(QPixmap(QString(":/image/one.jpg").arg(iconnamelist[i])).size());
            btn->setText(QString("%1").arg(namelist[i]));//设置名字
        }
        if(i==1)
        {
            btn->setIcon(QPixmap(QString(":/image/two.jpg").arg(iconnamelist[i])));
            btn->setIconSize(QPixmap(QString(":/image/two.jpg").arg(iconnamelist[i])).size());
            btn->setText(QString("%1").arg(namelist[i]));//设置名字
        }
        if(i==2)
        {
            btn->setIcon(QPixmap(QString(":/image/three.jpg").arg(iconnamelist[i])));
            btn->setIconSize(QPixmap(QString(":/image/three.jpg").arg(iconnamelist[i])).size());
            btn->setText(QString("%1").arg(namelist[i]));//设置名字
        }
        if(i==3)
        {
            btn->setIcon(QPixmap(QString(":/image/four.jpg").arg(iconnamelist[i])));
            btn->setIconSize(QPixmap(QString(":/image/four.jpg").arg(iconnamelist[i])).size());
            btn->setText(QString("%1").arg(namelist[i]));//设置名字
        }

        //设置透明
        btn->setAutoRaise(true);
        btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
        ui->verticalLayout_2->addWidget(btn);
        vector.push_back(btn);
        isshow.push_back(false);

    }
    for(int i=0;i<4;i++)
    {


        connect(vector[i],&QToolButton::clicked,[=](){
                    if(isshow[i])//已经被打开
                    {
                       QMessageBox::warning(this,"警告!","不能重复打开");
                        return;
                    }
                    isshow[i]=true;
            Widget *widget=new Widget(nullptr,vector[i]->text());
            widget->setWindowIcon(vector[i]->icon());
            widget->setWindowTitle(vector[i]->text());
            widget->show();
            connect(widget,&Widget::closeWidget,this,[=](){

                 isshow[i]=false;
            });
        });

    }


}

denglu::~denglu()
{
    delete ui;
}
